//
//  Number+Extension.swift
//  MattressTool
//
//  Created by Coder Yang on 2023/11/19.
//

import UIKit

protocol Adapterable {
    var rpx: CGFloat { get }
}

extension Adapterable {
    fileprivate var auto: CGFloat {
        if UIDevice().userInterfaceIdiom == .pad { // iPad
            return 1.09
        }
        
        let base = CGFloat(375.0)
        let width = CGFloat(UIScreen.main.bounds.width)
        let height = CGFloat(UIScreen.main.bounds.height)
        let minWidth = min(width, height)
        return (minWidth / base)
    }
}

extension Int: Adapterable {
    var rpx: CGFloat {
       (CGFloat(self) * auto).rounded()
    }
}

extension Double: Adapterable {
    var rpx: CGFloat {
        (CGFloat(self) * auto).rounded()
    }
}

extension CGFloat: Adapterable {
    var rpx: CGFloat {
        (self * auto).rounded()
    }
}

/// 顶部安全区高度
let topSafeArea = UIDevice.topSafeArea
/// 底部安全区高度
let bottomSafeArea = UIDevice.bottomSafeArea
/// 状态栏高度
let statusBarHeight = UIDevice.statusBarHeight
/// 导航高度
let navigationBarHeight = UIDevice.navigationBarHeight
/// 导航栏高度 + 顶部安全区高度
let navBarHeight = UIDevice.navBarHeight
/// 底部选项卡高度
let tabBarHeight = UIDevice.tabBarHeight
/// 底部选项卡高度 + 底部安全区高度
let tabBarSafeHeight = UIDevice.tabBarSafeHeight
